<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:p="http://primefaces.org/ui"
   xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
   template="/WEB-INF/templates/default.xhtml">
   
   	<f:metadata>
	   	<f:viewParam name="qualificationClassId" value="#{qualificationClassHome.id}"></f:viewParam>
	   	<f:event listener="#{qualificationClassHome.initConversation()}" type="preRenderView"></f:event>
	   	<f:viewParam name="moduleName" value="资质分类管理"></f:viewParam>
   	</f:metadata>
   
   	<ui:define name="content">
   
		<h:form id="editForm">         
			<p:panel id="panel" header="#{qualificationClassHome.managed ? '修改' : '新增'}资质分类" style="margin-bottom:10px;">
		       <p:messages id="messages" closable="true"><p:autoUpdate/></p:messages>
		        <p:remoteCommand name="updateLevelOptionPanel" update="levelOptionPanel"></p:remoteCommand>
		        <h:panelGrid columns="2" cellpadding="5">
		        
		        	<p:outputLabel for="name" value="资质类别名称" />				
					<p:inputText id="name" 
							  value="#{qualificationClassHome.instance.name}"
						   required="true"
						   readonly="#{qualificationClassHome.managed}" >
						<f:validator binding="#{qClassNameValidator}" disabled=""></f:validator>
						<f:ajax render="@this"  />
					</p:inputText>	   
						   
					<p:outputLabel for="rootSectors" value="行业名称" />	
					<p:selectManyCheckbox id="rootSectors" required="true" value="#{qualificationClassHome.instance.rootSectors}" layout="grid" columns="3" collectionType="java.util.LinkedHashSet">
						<f:selectItems value="#{rootSectorList.resultList}" var="_sector" itemLabel="#{_sector.sectorName}" itemValue="#{_sector}"></f:selectItems>
						<f:converter converterId="entityConverter"></f:converter>					
					</p:selectManyCheckbox>
						   
					<p:outputLabel for="auditDepartment" value="主管部门"></p:outputLabel>
					<p:selectOneMenu id="auditDepartment"
								  value="#{qualificationClassHome.instance.auditDepartment}"
							   required="true">
						<f:selectItem itemLabel="请选择" itemValue="#{null}" />		
						<f:selectItems value="#{serviceDepartmentList.resultList}" var="_dept" itemLabel="#{_dept.cnname}" itemValue="#{_dept}"></f:selectItems>
						<f:converter converterId="entityConverter"></f:converter>						
					</p:selectOneMenu>
					
					<p:outputLabel value="资质等级"></p:outputLabel>
					<p:panel styleClass="levelOptionPanel" id="levelOptionPanel" widgetVar="levelOptionPanel">
						<h:panelGrid columns="5" cellpadding="5">
							<c:forEach var="_levelOption" items="#{qualificationClassHome.instance.levelOptions}" varStatus="_status">
								<p:outputLabel for="optionName#{_levelOption.levelIndex}" value="等级标题"></p:outputLabel>
								<p:inputText id="optionName#{_levelOption.levelIndex}" value="#{_levelOption.name}" />
								
								<p:outputLabel for="optionValue#{_levelOption.levelIndex}" value="等级值"></p:outputLabel>
								<p:inputText id="optionValue#{_levelOption.levelIndex}" value="#{_levelOption.value}" />
								
								<p:commandButton action="#{qualificationClassHome.instance.removeLevelOption(_levelOption.levelIndex)}" 
											oncomplete="updateLevelOptionPanel()"
											  immediate="true"
											  	  value="删除"></p:commandButton>
							</c:forEach>
						</h:panelGrid>
						
						<p:commandButton action="#{qualificationClassHome.instance.addEmptyLevelOption()}" 
									oncomplete="updateLevelOptionPanel()"
									  immediate="true"
									  	  value="新增"></p:commandButton>
					</p:panel>			
				</h:panelGrid>
			</p:panel>
			
			<p:commandButton action="#{qualificationClassHome.saveAndFlush()}" value="保存" ajax="false" />
			<p:commandButton value="删除" action="#{qualificationClassHome.delete()}">
				<p:confirm header="请确认" message="您确认删除记录吗?" icon="ui-icon-alert" />
			</p:commandButton>
			<p:commandButton action="#{qualificationClassHome.cancel()}" value="取消" immediate="true"></p:commandButton>			
			
			<p:confirmDialog id="confirmDialog" global="true" showEffect="fade" hideEffect="explode" widgetVar="confirmDialog">
			    <p:commandButton value="确认" styleClass="ui-confirmdialog-yes"></p:commandButton>
			    <p:commandButton value="取消" immediate="true" styleClass="ui-confirmdialog-no" />
			</p:confirmDialog>
		</h:form>
      
   	</ui:define>
</ui:composition>
